from LeetCoder import *


class Solution:

    def differenceOfDistinctValues(self,
                                   grid: List[List[int]]) -> List[List[int]]:
        m, n = len(grid), len(grid[0])
        ans = [[0] * n for _ in range(m)]
        for i in range(m):
            for j in range(n):
                s = set()
                if n > 0 and m > 0:
                    for k in range(1, min(i, j) + 1):
                        s.add(grid[i - k][j - k])
                l = len(s)
                s = set()
                if i < m - 1 and j < n - 1:
                    for k in range(1, min(m - i, n - j)):
                        s.add(grid[i + k][j + k])
                ans[i][j] = abs(l - len(s))

        return ans

s = Solution()
print(s)
